import ajax from "@/utils/request";
/**
 * 获取文章的列表
 * @param {channel_id,timestamp} obj
 */
export const getArticles = obj => {
  const { channel_id, timestamp } = obj;
  return ajax({
    method: "GET",
    url: "/app/v1_1/articles",
    params: {
      with_top: 1,
      timestamp: timestamp,
      channel_id: channel_id
    }
  });
  ///app/v1_1/articles?with_top=1
};
/**
 * 文章更多操作-----不喜欢 指定id 的文章
 * @param {*} articleId 文章id
 */
export const dislikeArticle = articleId => {
  return ajax({
    method: "POST",
    url: "/app/v1_0/article/dislikes",
    data: {
      target: articleId
    }
  });
};
/**
 * 举报文章
 * @param {*} articleId 文章类型
 * @param {*} type 举报类型编号
 */
export const reportArticle = (articleId, type) => {
  return ajax({
    method: "POST",
    url: "/app/v1_0/article/reports",
    data: {
      target: articleId,
      type
    }
  });
};
/**
 * 获取文章详情
 * @param {*} id 文章编号
 */
export const getArticle = id => {
  return ajax({
    method: "GET",
    url: "/app/v1_0/articles/" + id
  });
};

/**
 * 固定套路
 */
// export const xxxx  = () =>{
//   return ajax({

//   })
// }
/**
 * 取消关注用户
 * @param {*} id
 */
export const deleteFollowing = id => {
  return ajax({
    url: "/app/v1_0/user/followings/" + id,
    method: "DELETE"
  });
};
/**
 * 关注 用户
 * @param {*} id
 */
export const postFollow = id => {
  return ajax({
    method: "POST",
    url: "/app/v1_0/user/followings",
    data: {
      target: id
    }
  });
};
/**
 * 对文章点赞
 * @param {*} id
 */
export const likeArticle = id => {
  return ajax({
    url: "/app/v1_0/article/likings",
    method: "POST",
    data: {
      target: id
    }
  });
};
export const desLikeArticle = id => {
  return ajax({
    url: "/app/v1_0/article/likings/" + id,
    method: "DELETE"
  });
};
/**
 * 添加对文章不喜欢
 * @param {*} id
 */
export const AddDisloveArticle = id => {
  return ajax({
    url: "/app/v1_0/article/dislikes",
    method: "POST",
    data: {
      target: id
    }
  });
};
/**
 * 取消对文章不喜欢
 * @param {*} id
 */
export const CancelLoveArticle = id => {
  return ajax({
    url: "/app/v1_0/article/dislikes/" + id,
    method: "DELETE"
  });
};
